package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    //private static String[] paramList ={"username","phone","email"};//->这么写也行就是写死了,老师说map更好
    private static Map<Integer,String> paramMap=new HashMap<>();
    static {
        paramMap.put(1,"username");
        paramMap.put(2,"phone");
        paramMap.put(3,"email");
    }

    /**
     * 根据用户传递的参数获取数据库记录
     * @param param 传递的参数
     * @param type 字段->1 username、2 phone、3 email
     * @return
     */
    @Override
    public Boolean checkUser(String param, Integer type) {

        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        //queryWrapper.eq(paramList[type-1], param);
        queryWrapper.eq(paramMap.get(type), param);
        Integer count = userMapper.selectCount(queryWrapper);
        return count>0;//是否存在->是否为0
        //...
    }

    @Override
    public List<User> findUserList() {
        return userMapper.selectList(null);
    }
}
